package com.sjqg.dao;
import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import com.sjqg.model.Book;


public class BookDao extends BaseDao  {
	public Boolean addBook(Book book) {
		try {
			String sql = "insert into books"
					+ " (id, serviceid, userName, booktime, price, message)"
					+ " values"
					+ " (?, ?, ?, ?, ?, ?)";
			return queryRunner.execute(sql 
					, book.getId()
					, book.getService().getId()
					, book.getUser().getNickName()
					, book.getBookTime()
					, book.getPrice()
					, book.getMessage()) == 1;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public Book getMaxId() {
		try {
			String sql = "select max(id) id from books";
			return queryRunner.query(sql, new BeanHandler<>(Book.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
